<template>
    <div class="loginpages">

    </div>
</template>

<script setup>
import { useRoute } from 'vue-router'
import { useHttp } from "~/api/http";
import { ref } from 'vue'
import { useRouter } from 'vue-router';
import { setToken, setUserId,removeToken,removeUserId,setUserPermission } from '@/utils/token'



const router = useRouter()
const route = useRoute()


if (route.query.hasOwnProperty('logincode') && route.query.logincode !== '') {
    const logincode = route.query.logincode;
    removeToken()
    removeUserId()
    useHttp.post('/sys/oaLogin', {
        username: logincode
    }).then(res => {
        
        if (res.code == 200) {
            setToken(res.result.token);
            setUserId(res.result.userInfo.id);
            
           
            message.success(res.message);
            userPermission()
        }
    }).catch(err => {
        router.push({ path: '/' });
        message.error(err.message); 
    });
} else {
    router.push({ path: '/' });
}

// 查看账号权限
const userPermission = () => {
    useHttp.get('/sys/permission/getUserPermissionByToken').then(res => {
    }).catch(res => {
      if(res.code == 0) {
        let userPermission = {}
        for(let i of res.result.codeList) {
          userPermission[i] = 1
        }
        setUserPermission(userPermission)
         window.location.href = '/'
       
      }
    })
    

}


</script>

<style lang="less" scoped>
.loginpages {
    width: 100%;
    height: 100%;
    z-index: 100;
}
</style>